package com.fyk.controller;

import com.fyk.entity.Book;
import com.fyk.entity.User;
import com.fyk.service.BookService;
import com.fyk.service.UserService;
import com.fyk.utils.ResultUtils;
import com.sun.org.apache.regexp.internal.REUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author qazws
 * @Date 2022/8/19 17:29
 * @Version 1.0
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private BookService bookService;

    @RequestMapping("/user/{url}")
    public ResultUtils User(@PathVariable String url, User user){
        switch (url){
            case "login":
                return userService.login(user);
            case "updateUser":
                return userService.updateUser(user);
            case "findUser":
                return userService.findUser();
            case "insertUser":
                return userService.insertUser(user);
            case "outUser":
                return userService.outUser();
        }
        return null;
    }

    @RequestMapping("/userBook/{url}")
    public ResultUtils UserBook(@PathVariable String url, Book book){

        switch (url){
            case "user-bookList":
                return bookService.selectAllBook(book);
            case "user-findBook":
                return bookService.findBook(book);
            case "user-borrowBook":
                return bookService.borrowBook(book);
            case "user-returnBookList":
                return bookService.returnBookList(book);
            case "user-returnFindBookList":
                return bookService.returnFindBookList(book);
            case "user-returnBook":
                return bookService.returnBook(book);
        }
        return null;
    }
}
